package pailiewu.util;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

/**
 * HTTP工具类. 下载P5.txt文件到本地
 * 
 * @author roadmate
 */
public class HttpUtil {

	
	/**
	 * 下载文件到本地
	 *
	 * @param urlString
	 *            被下载的文件地址
	 * @param filename
	 *            本地文件名
	 * @throws Exception
	 *             各种异常
	 */
	public static void download(String urlStr,String fileStr) throws Exception {
		System.out.println("urlStr is "+urlStr);
		System.out.println("fileStr is "+fileStr);
		URL url = new URL(urlStr);
		InputStream inStream = url.openStream();
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));

		FileWriter fw = new FileWriter(fileStr);
		BufferedWriter bufferedWriter = new BufferedWriter(fw);

		String line = "";
		while ((line = bufferedReader.readLine()) != null) {
			bufferedWriter.write(line);
			bufferedWriter.newLine();
		}
		bufferedReader.close();
		bufferedWriter.close();

	}
	

}
